<?php

namespace App\Modules\LuckDraw\Message;

use App\Http\Services\CommonRoomMsgServices;
use App\Http\Services\MsgServices;
use Illuminate\Support\Facades\Redis;


class WorldCupMessage implements MessageInterface {
    private $_name = "world_cup";
    private $_messageModel;
    public function __construct($messageModel){
        $this->_messageModel = $messageModel;
    }

    //具体发送逻辑
    public function send(?array $data = null):?bool{
        $roomId = 0;
        $user = [];
        $awards = [];
        //获取飘屏消息模版
        $screenId = $this->getScreenId();

        //获取用户信息
        if (isset($data['user'])){
            $user = $data['user'];
        }
        //获取奖品列表
        if (isset($data['awards'])) {
            $awards = $data['awards'];
        }

        foreach ($awards as $award) {
            if ($award->price >= $this->getMinPrice()) {
                //发送飘屏消息
//                if ($award->price >= 100000) {
                $extendParam = [];
                $extendParam['roomId'] = $roomId;
                $extendParam['giftPrice'] = $award->price;
                (new MsgServices())->sendFullScreen($screenId, $award->image, ['name' => $user['nickname'], 'gift' => $award->name,  'num' => $award->num], [], $extendParam);
//                }
            }
        }
        return true;
    }

    public function getMinPrice(): int{
        return $this->_messageModel->min_price??0;
    }
    public function getRoomMsg():string{
        return $this->_messageModel->room_msg??'';
    }
    public function getScreenId():int{
        return $this->_messageModel->screen_id??0;
    }
}